from kivy.uix.floatlayout import FloatLayout
from kivy.properties import BooleanProperty, ListProperty, ObjectProperty
from kivy.uix.screenmanager import ScreenManager, Screen

from kivy.lang import Builder

import guiCommon
import sidePanel
import wineSelectorWidgets

class MainScreenBase(Screen):
    _mainListContainer = ObjectProperty(None)
    _button_bar = ObjectProperty(None)


    def initialize(self):
        # init WineButtonBar
        quickSelBar = self._button_bar.children[0]
        #self._button_bar.children[0].initFastInstances()
        self.quickColorSelector = quickSelBar.colorSelector()
        self.quickTextSelector  = quickSelBar.textSelector()

    def quickSelectors(self):
        return [self.quickColorSelector, self.quickTextSelector ] 
        

class MainScreenDouble(MainScreenBase):
    """The main screen with  2 items (list of wines, details of a bottle,...) displayed side by side.
    Used in desktop application.
    """
    _sidepanel = ObjectProperty(None)

class MainScreenSingle(MainScreenBase):
    """The main screen with only one item (list of wines, details of a bottle,...) displayed
    Used on mobile device in portrait mode.
    """
    pass


class WModeButtonBar(guiCommon.ModeButtonBar):
    pass

class QuickWineSelBar(guiCommon.LeVinButtonBar):
    def __init__(self, **args):
        super(QuickWineSelBar,self).__init__(**args)
        print 'QuickWineSelBar ',self.children


    def colorSelector(self):
        for c in self.children:
            if isinstance(c, wineSelectorWidgets.ColorSelectorWid):
                return c
    def textSelector(self):
        for c in self.children:
            if isinstance(c, wineSelectorWidgets.TextSelectorWid):
                return c

    def initFastInstances(self):
        for c in self.children:
            if isinstance(c, wineSelectorWidgets.ColorSelectorWid):
                wineSelectorWidgets.ColorSelectorWid.mainInstance = c
            elif isinstance(c, wineSelectorWidgets.TextSelectorWid):
                wineSelectorWidgets.TextSelectorWid.mainInstance = c
        
            elif isinstance(c, wineSelectorWidgets.NumSelectorWid):
                wineSelectorWidgets.NumSelectorWid.mainInstance = c


from kivy.factory import Factory
for cls in [QuickWineSelBar, WModeButtonBar]:
    Factory.register(cls.__name__, cls=cls)

guiCommon.load_kv_file('mainScreen.kv')
    

#wineSelectorWidgets.initialize()
